package com.vincent.kdp.js;

import android.app.Activity;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.vincent.kdp.Activity.GetGoodsDetailActivity;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.ui.bean.response.BaseOutput;
import com.vincent.kdp.ui.fragment.repository.CommodityRepository;
import com.vincent.kdp.util.BaseParam;

/**
 * Created by jingjing on 2017/3/10.
 */

public class GetGoodsDetailOperator {

    private String barCode;
    private GetGoodsDetailActivity mActivity;
    private CommodityRepository mCommodityRepository;
    public GetGoodsDetailOperator(GetGoodsDetailActivity mActivity,String barCode){
        this.barCode=barCode;
        this.mActivity=mActivity;
        mCommodityRepository=new CommodityRepository();
    }

    @JavascriptInterface
    public String getBarCode(){
        return barCode;
    }

    @JavascriptInterface
    public String getDeviceId(){
        return BaseParam.getDeviceId();
    }

    @JavascriptInterface
    public void addApplyGetGoods(String id,String content){
        Log.i("code","商品ID："+id+"----内容："+content);
        mCommodityRepository.reqApplyGoods(id, content, new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {
                BaseOutput baseOutput= (BaseOutput) object;
                if(baseOutput.getMsg().equals("请求成功")){
                    Toast.makeText(mActivity,"申请调货成功",Toast.LENGTH_SHORT).show();
                    mActivity.finish();
                }else{
                    Toast.makeText(mActivity,baseOutput.getMsg(),Toast.LENGTH_SHORT).show();
                }
            }
            @Override
            public void onFalse(String msg) {
                Toast.makeText(mActivity,msg,Toast.LENGTH_SHORT).show();
            }
        });
    }
}
